package org.example.object.notify2;

public class Buffer {
    private Integer value = null;

    public synchronized void offer(int value) {
        while (this.value != null) {
            try {
                wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        this.value = value;
        notifyAll();
    }

    public synchronized int take() {
        while (this.value == null) {
            try {
                wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        int temp = this.value;
        this.value = null;
        notifyAll();
        return temp;
    }
}
